﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <title>月度产能看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 24px;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">燃烧部件事业部月度产能看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="筛选时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handlerBtnSearch">查询</el-button>
        </el-form-item>
      </el-form>

      <dv-border-box-11 title="各工区月度产能">
        <div style="height: 360px;padding-top: 40px;" id="workcenterChart"></div>
      </dv-border-box-11>

      <dv-border-box-11 title="各班组月度产能">
        <div style="height: 360px;padding-top: 40px;" id="teamChart"></div>
      </dv-border-box-11>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    const app = new Vue({
      el: '#app',
      data: {
        currentTime: '',
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { factoryid: '', selectdate: '' },
        rules: { selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        async getWorkcenterChartData() {
          const dom = document.getElementById("workcenterChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/RSFactoryMonthCapacityDashBoard.ashx?action=getWorkcenterChartData', {
            type: 'getWorkcenterChartData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status == 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrWorkcenter = [], arrPlanTime = [], arrFinishTime = [], arrFinishRate = [];
          for (const i of data) {
            arrWorkcenter.push(i.workcentername);
            arrPlanTime.push(i.planedtime);
            arrFinishTime.push(parseFloat(i.finishtime).toFixed(2));
            arrFinishRate.push(i.finishrate);
          }

          let option = barOption();
          option.yAxis[1].axisLabel.formatter = data => data + "%";

          option.legend.data = ['计划产能', '实际产能', '完成率'];
          option.xAxis.data = arrWorkcenter;

          option.series[0] = _.merge(option.series[0], {
            name: '计划产能',
            data: arrPlanTime,
            barMaxWidth: 35,
            barGap: '70%',
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '实际产能',
            data: arrFinishTime,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '完成率',
            data: arrFinishRate,
            type: 'line',
            symbolSize: 10,
            lineStyle: { width: 3, color: colorList.red.color },
            label: { color: colorList.red.color },
            itemStyle: { color: colorList.red.color },
            yAxisIndex: 1
          });
          chart.setOption(option);
        },
        async getTeamChartData() {
          const dom = document.getElementById("teamChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/RSFactoryMonthCapacityDashBoard.ashx?action=getTeamChartData', {
            type: 'getTeamChartData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status == 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrTeam = [], arrPlanTime = [], arrFinishTime = [], arrFinishRate = [];
          for (const i of data) {
            arrTeam.push(i.teamname)
            arrPlanTime.push(i.planedtime)
            arrFinishTime.push(parseFloat(i.finishtime).toFixed(2))
            arrFinishRate.push(i.finishrate)
          }

          let option = barOption();
          option.yAxis[1].axisLabel.formatter = data => data + "%";
          option.legend.data = ['计划产能', '实际产能', '完成率'];
          option.xAxis.data = arrTeam;

          option.series[0] = _.merge(option.series[0], {
            name: '计划产能',
            data: arrPlanTime,
            barMaxWidth: 35,
            barGap: '70%',
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '实际产能',
            data: arrFinishTime,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '完成率',
            data: arrFinishRate,
            type: 'line',
            symbolSize: 10,
            lineStyle: { width: 3, color: colorList.red.color },
            label: { color: colorList.red.color },
            itemStyle: { color: colorList.red.color },
            yAxisIndex: 1
          });
          chart.setOption(option);
        },
        handlerBtnSearch() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.getWorkcenterChartData();
              this.getTeamChartData();
            }
          })
        }
      },
      mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        const today = dayjs().format('YYYY-MM-DD');
        const factoryid = Decrypt(getParams('factoryid'));
        this.queryInfo.factoryid = factoryid;
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfThisMonth, endOfThisMonth]
        this.getWorkcenterChartData()
        this.getTeamChartData()
      }
    })
  </script>
</body>

</html>